export default {
  namespaced: true,
  state: {
    snapshot: '',
    redoArr: [],
    undoArr: [],
    rectArr:[],
    tableArr:[],
    templateList: [],
    coordinatesList: [],
    imageInfo: {
      left: 0,
      top: 0,
      width: 0,
      height: 0
    },
  },
  mutations: {
    SAVE_SNAPSHOT (state, payload) {
      state.snapshot = payload;
    },
    SET_SNAPSHOT (state, type) {
      state.snapshot = (type === 'undo' ? state.undoArr : state.redoArr).pop();
    },
    SET_TABLE_LIST(state, data) {
      state.tableArr = data;
    },
    SET_UNDO_LIST (state) {
      state.undoArr.push(state.snapshot);
    },
    SET_REDO_LIST (state) {
      state.redoArr.push(state.snapshot);
    },
    SET_IMAGE_INFO (state, payload) {
      state.imageInfo = {...payload};
    },
    CLEAR_UNDO_LIST (state) {
      state.undoArr = [];
    },
    CLEAR_REDO_LIST (state) {
      state.redoArr = [];
    }
  },
  actions: {
    setCoordinatesList ({ commit, state }, payload) {
      const template = payload.filter(item => {return item.objectType !== 'copy'})
      state.coordinatesList = template.map(item => {
        const coordinates = formCoordinate(state.imageInfo, item);
        const columnLineCoordinateList = formCoordinateColumn(state.imageInfo, item);
        return {
          type:item.objectType,
          objectId:item.objectId,
          coordinates,
          columnLineCoordinateList
        }
      })
      console.log('coordinatesList', JSON.parse(JSON.stringify(state.coordinatesList)))
    }
  }
};